import pandas as pd

current_price = 100  # 当前价格
grid_size = 5 # 网格大小
lower_limit = 90  #下限价格
upper_limit = 110  # 上限价格
shares_per_grid = 100  # 每格交易份额

grids = [(i, lower_limit + i * grid_size) for i in range(0, int((upper_limit - lower_limit) // grid_size) + 1)]  
print("grids",grids)
def trade_simulation(current_price):
    for grid_idx,grid_price in grids:
        if current_price <= grid_price:
            buy_shares = shares_per_grid
            print(f"当前价格{current_price}触及网格{grid_idx},执行买入操作,买入份额:{buy_shares}")
            break
        elif current_price >= upper_limit - grid_price * grid_size:
            sell_shares  = shares_per_grid
            print(f"当前价格{current_price}触及网格{grid_idx},执行卖出操作,买入份额:{sell_shares}")
            break
    print(f"当前价格:{current_price},检查止损止盈条件。。。")
prices = [95, 97, 100, 103, 105, 108, 110]  
for price in prices:  
    trade_simulation(price)  
